package com.ftf.tp.message.domain.directMessage.service.impl.impl;

import com.ftf.tp.message.domain.directMessage.dos.NoticeDO;
import com.ftf.tp.message.domain.directMessage.dos.NoticeSettingConfigDO;
import com.ftf.tp.message.domain.directMessage.repository.NoticeRepository;
import com.ftf.tp.message.domain.directMessage.repository.UserNoticeConfigRepository;
import com.ftf.tp.message.domain.directMessage.service.impl.NoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author tanghao
 * @date 2022/9/16
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    @Resource
    private UserNoticeConfigRepository userNoticeConfigRepository;

    @Resource
    private NoticeRepository noticeRepository;

    /**
     * 该消息的接收对象是否接受该消息
     *
     * @param userId     接受对象id
     * @param i          消息类型
     * @param targetType 消息主体对象类型
     * @return 结果
     */
    @Override
    public boolean isReceive(Long userId, int i, String targetType) {
        return !userNoticeConfigRepository.exitConfig(userId, i, targetType);
    }

    /**
     * 生成通知
     *
     * @param noticeDO 通知实体
     */
    @Override
    public void created(NoticeDO noticeDO) {
        noticeRepository.insert(noticeDO);
    }

    /**
     * 获取通知配置
     *
     * @param i          消息类型
     * @param targetType 消息主体对象类型
     */
    @Override
    public NoticeSettingConfigDO getNoticeSettingConfig(int i, String targetType) {
        return userNoticeConfigRepository.getNoticeSettingConfig(i, targetType);
    }
}
